//
//  AppDelegate.swift
//  fsapp
//
//  Created by zguang on 17/7/26.
//  Copyright © 2017年 huangshengjie. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        
        
        if let cookieArray = UserDefaults.standard.array(forKey: "savedCookies") {
            for cookieData in cookieArray {
                if let dict = cookieData as? [HTTPCookiePropertyKey : Any] {
                    if let cookie = HTTPCookie.init(properties : dict) {
                        HTTPCookieStorage.shared.setCookie(cookie)
                    }
                }
            }
        }
        

        
        self.window?.rootViewController = LoadViewController()
       // self.window?.rootViewController = UINavigationController(rootViewController:LoginViewController())
        self.window?.makeKeyAndVisible()
        
        
        
               
        // Override point for customization after application launch.
        return true
    }
    
    
    func tick(){
        let usd = UserSave()
        print(usd.readInfo())
        let loginNav = UINavigationController(rootViewController:LoginViewController());
        if usd.readInfo().count<2{
            
        }
        else{
            if usd.readInfo()[2] == ""{
                self.window?.rootViewController = loginNav
            }else{
                self.window?.rootViewController = CusTomTabBar()
            }
        }
        
        
        
    }
    
    
    func CusTomTabBar() ->UITabBarController{
        let vc1 = IndexViewController()
        let vc2 = FillLearningViewController.init(typee: "0")
        let vc3 = FillLearningViewController.init(typee: "1")//FAQViewController()
        let vc4 = FillLearningViewController.init(typee: "2")
        let vc5 = MineViewController()

        let vcRegist = RegistViewController()
        let nvc1:UINavigationController = UINavigationController(rootViewController: vc1)
        let nvc2:UINavigationController = UINavigationController(rootViewController: vc2)
        let nvc3:UINavigationController = UINavigationController(rootViewController: vc3)
        let nvc4:UINavigationController = UINavigationController(rootViewController: vc4)
        let nvc5:UINavigationController = UINavigationController(rootViewController:vc5)
        let tabbar1 = UITabBarItem(title: "首页", image:#imageLiteral(resourceName: "主页"), selectedImage: #imageLiteral(resourceName: "主页"))
        let tabbar2 = UITabBarItem(title: "完整学习", image:#imageLiteral(resourceName: "完整学习副本"), selectedImage: #imageLiteral(resourceName: "完整学习副本"))
        let tabbar3 = UITabBarItem(title: "学习解惑", image:#imageLiteral(resourceName: "学习解惑"), selectedImage:#imageLiteral(resourceName: "学习解惑"))
        let tabbar4 = UITabBarItem(title: "生活应用", image:#imageLiteral(resourceName: "生活应用"), selectedImage: #imageLiteral(resourceName: "生活应用"))
        let tabbar5 = UITabBarItem(title: "我的", image:#imageLiteral(resourceName: "我的"), selectedImage: #imageLiteral(resourceName: "我的"))
        nvc1.tabBarItem = tabbar1;
        nvc2.tabBarItem = tabbar2;
        nvc3.tabBarItem = tabbar3;
        nvc4.tabBarItem = tabbar4;
        nvc5.tabBarItem = tabbar5;
        let tc = UITabBarController()
        tc.tabBar.tintColor = naviColor
        nvc1.navigationController?.title = "首页"
        nvc2.title = "完整学习"
        nvc3.title = "学习解惑"
        nvc4.title = "生活应用"
        nvc5.title = "我的"
        tc.viewControllers = [nvc1,nvc2,nvc3,nvc4,nvc5]
        // tc.tabBar.backgroundImage = Public.getImgView("3.png")tc.viewControllers = [nvc1,nvc2,nvc3,nvc4,nvc5];return tc;
        return tc
    }
    


    
        
        func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

